package cn.org.donald.framework.config;

import cn.org.donald.framework.constant.FileConstant;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author ： Donald
 * @date ： 2020/10/24 15:39
 * @description：
 */
@Configuration
public class WebMvcConfig implements WebMvcConfigurer {

    /**
     * 跨域请求配置
     * @param registry
     */
    @Override
    public void addCorsMappings(CorsRegistry registry){
        registry.addMapping("/**").allowedOrigins("*")
                .allowedMethods("GET","HEAD","POST","PUT","DELETE","OPTIONS")
                .allowCredentials(false).maxAge(3600);
    }


    /**
     * 下载文件路径访问地址
     * @param registry
     */
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler(FileConstant.FILE_PATH_REQUEST+"**").addResourceLocations(FileConstant.FILE_PATH_REAL);

    }
}
